import com.txm.qqcommon.Message;
import com.txm.qqcommon.MessageType;
import com.txm.qqcommon.User;
import com.txm.qqview.QQView;
import com.txm.service.ClientConnectServerThread;
import com.txm.service.UserClientService;

import java.util.HashMap;

// 按两次 Shift 打开“随处搜索”对话框并输入 `show whitespaces`，
// 然后按 Enter 键。现在，您可以在代码中看到空格字符。
public class Main {
    public Main() {
        QQView qqView = new QQView();
        try {
            while (true) {
                qqView.getLoginView();
                if (qqView.choice_char == '1') {
                    HashMap<String, String> account = qqView.getAccount();
//                System.out.println("account：" + account);
                    UserClientService userClientService = new UserClientService();

                    Message message = userClientService.checkUser(account.get("username"), account.get("password"));
//                    System.out.println("服务器返回的数据：" + message);
                    if (message.getMsgType().equals(MessageType.MESSAGE_LOGIN_SUCCEED)) {
                        System.out.println(message.getContent());
                        qqView.userName = message.getGetter();
                        qqView.choice_char = '\u0000';
                        ClientConnectServerThread cCST = new ClientConnectServerThread(userClientService.getSocket(), qqView);
                        User u = (User) message.getObject();
                        cCST.user = u;
                        cCST.setName(u.getUsername() + Message.getLocalDate());

                        cCST.start();
                        qqView.getMainView();
                        break;
                    } else {
                        System.out.println(message.getContent());
                        userClientService.getSocket().close();
                    }
                }
            }
        } catch (Exception e) {
//            System.out.println("验证失败：" + e);
        }
    }

    public static void main(String[] args) {
        Main main = new Main();


    }


}